1 /*
2 * (C) 2002 David Carr david@carr.name
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 package net.sourceforge.mflow.config;
20 import java.awt.Canvas;
21 import java.awt.Graphics;
22 import java.awt.Rectangle;
23 import java.awt.Window;
24 import java.awt.event.MouseEvent;
25 import java.awt.event.MouseListener;
26 import java.beans.PropertyEditor;
27
28 /***
29 * Class to link a Canvas with a PropertyEditor
30 *
31 * @author <a href="mailto:david@carr.name">David Carr</a>
32 * @version $Revision: 1.4 $
33 */
34 class PropertyCanvas extends Canvas implements MouseListener {
35 /***
36 * Flag for ignoring clicks
37 */
38 private boolean ignoreClick = false;
39 /***
40 * Private reference to the parent window
41 */
42 private Window frame;
43 /***
44 * Private reference to the property editor
45 */
46 private PropertyEditor editor;
47
48 /***
49 * Constructor taking a parent window and a property editor
50 *
51 * @param frame the parent window
52 * @param pe the property editor
53 */
54 PropertyCanvas(Window frame, PropertyEditor pe) {
55 this.frame = frame;
56 this.editor = pe;
57 addMouseListener(this);
58 }
59
60 /***
61 * Paints the canvas using the passed Graphics object
62 *
63 * @param g the Graphics object to use to paint the Canvas
64 */
65 public void paint(Graphics g) {
66 Rectangle box =
67 new Rectangle(2, 2, getSize().width - 4, getSize().height - 4);
68 this.editor.paintValue(g, box);
69 }
70
71 /***
72 * Launches a PropertyDialog if appropriate
73 *
74 * @param evt the event
75 */
76 public void mouseClicked(MouseEvent evt) {
77 if (!this.ignoreClick) {
78 try {
79 this.ignoreClick = true;
80 int x = this.frame.getLocation().x - 30;
81 int y = this.frame.getLocation().y + 50;
82 new PropertyDialog(this.frame, this.editor, x, y);
83 } finally {
84 this.ignoreClick = false;
85 }
86 }
87 }
88
89 /***
90 * Not used
91 *
92 * @param evt the event
93 */
94 public void mousePressed(MouseEvent evt) {
95 //Not used
96 }
97
98 /***
99 * Not used
100 *
101 * @param evt the event
102 */
103 public void mouseReleased(MouseEvent evt) {
104 //Not used
105 }
106
107 /***
108 * Not used
109 *
110 * @param evt the event
111 */
112 public void mouseEntered(MouseEvent evt) {
113 //Not used
114 }
115
116 /***
117 * Not used
118 *
119 * @param evt the event
120 */
121 public void mouseExited(MouseEvent evt) {
122 //Not used
123 }
124 }
This page was automatically generated by Maven